package demo01;

/**
 * @author mubei
 * @date 2021/11/20
 * @description
 */
// 多个线程操作同一个资源会产生数据紊乱
public class TestThread3 implements Runnable{

    //票数
    private int ticketNums = 10;
    @Override
    public void run() {
        while(true){
            if(ticketNums<=0){
                break;
            }
            System.out.println(Thread.currentThread().getName()+"--拿到了第:"+ticketNums--);
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


    public static void main(String[] args) {
        TestThread3 testThread3 = new TestThread3();
        new Thread(testThread3,"ah").start();
        new Thread(testThread3,"老师").start();
        new Thread(testThread3,"小米").start();

    }
}
